<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="dbexp.model.db.DbUser"%>
<%@page import="dbexp.model.*"%>
<%@page import="dbexp.model.db.DbOT"%>
<%@page import="dbexp.connection.DbConnection"%>
<%@page import="dbexp.connection.DbMetaData"%>
<%@page import="dbexp.model.Package"%>
<%@page import="dbexp.connection.PoolManagerException"%>
<%@page import="dbexp.connection.DbAccessException"%>
<%@page import="dbexp.connection.DbStateException"%>
<%@page import="dbexp.connection.DbQueryException"%>
<%@page import="java.sql.SQLException"%>
    <%
    		HttpServletRequest req = null;
	String name=request.getParameter("name");
	String schema=request.getParameter("schema");
	int type = DbOT.UNKNOWN;
			try{
				type=Integer.parseInt(request.getParameter("type"));
			}catch(Exception e){}
    String ddl = "";
    DbUser  u = (DbUser)session.getAttribute("USER");
		if(u!=null && name!=null && (schema!=null || type==DbOT.USER) & type!=DbOT.UNKNOWN){
			DbObject o = new DbObject(name,schema,type);
			try {
				if(u!=null){
					String info = "";
					if(o.isSequence() ){
						o =  DbMetaData.getSequence(u, name, schema);
					}else if(o.isView()){
						o = DbMetaData.getView(u,name,schema);
					}else if(o.isFunction()){
						o =  DbMetaData.getFunction(u,name,schema);
					}else if(o.isPackage()){
						o =  DbMetaData.getPackage(u,name,schema);
					}else if(o.isPackagebody()){
						o =  DbMetaData.getPackageBody(u,name,schema);
					}else if(o.isProcedure()){
						o =  DbMetaData.getProcedure(u,name,schema);
					}else if(o.isTable()){
						o =  DbMetaData.getTable(u,name,schema);
					}else if(o.isTrigger()){
						o =  DbMetaData.getTrigger(u,name,schema);
					}else if(o.isUser()){
						o =  DbMetaData.getUser(u,name);
						((User)o).setPassword("*****");
					}else if(o.isSynonim()){
						o =  DbMetaData.getSynonym(u,name, schema);
					}else if(o.isIndex()){
						o =  DbMetaData.getIndex(u,name, schema);
					}
				}
				ddl = o.getQuery(DbConnection.CREATE);//select DBMS_METADATA.GET_DDL('TABLE','TEST','MICHAL') FROM dual
				if(o.isSource()&& ((SourceType)o).isWrapped()){
					ddl =  ((SourceType)o).getContent();
				}
			} catch (PoolManagerException e) {
				e.printStackTrace();
			} catch (DbAccessException e) {
				e.printStackTrace();
			} catch (DbStateException e) {
				e.printStackTrace();
			} catch (DbQueryException e) {
				e.printStackTrace();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		out.clearBuffer();%><%=ddl%>